package com.ly.hotel.spainterface.jxd.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.spainterface.jxd.adapter.XFBillAdapter;
import com.ly.hotel.spainterface.nm.bean.XFBillBean;

import java.util.List;

/**
 * Created by SHUBEN on 2018/3/24.
 */

public class XFBillDialog extends Dialog {
    private Context mcontext;
    private ListView billListView;
    private XFBillAdapter xfBillAdapter;
    private List<XFBillBean> billList;
    private TextView billPricetext;
    private TextView billAddMsg;
    private TextView msg1;
    private TextView msg2;
    private TextView msg3;
    private TextView msg4;
    private TextView msg5;
    private TextView msg6;
    private double totalP;
    private String addmsg;


    public XFBillDialog(Context context) {
        super(context);
        mcontext = context;
    }

    public XFBillDialog(Context context,int theme, List<XFBillBean> list,double totalPrice) {
        super(context,theme);
        this.mcontext = context;
        this.billList = list;
        this.totalP = totalPrice;
    }

    public void setAddMsg(String s){
        addmsg = s;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xf_bill_layout);

        billListView = findViewById(R.id.xf_bill_list);
        billPricetext = findViewById(R.id.xf_bill_total_price);
        billAddMsg = findViewById(R.id.bill_add_msg);
        msg1 = findViewById(R.id.bill_text1);
        msg2 = findViewById(R.id.bill_text2);
        msg3 = findViewById(R.id.bill_text3);
        msg4 = findViewById(R.id.bill_text4);
        msg5 = findViewById(R.id.bill_text5);
        msg6 = findViewById(R.id.bill_text6);

        if(MyApplication.interfaceVersion.contains("JXD")){
            msg1.setText(mcontext.getString(R.string.bill_hand_card));
            msg2.setText(mcontext.getString(R.string.bill_item));
            msg3.setText(mcontext.getString(R.string.bill_category));
            msg4.setText(mcontext.getString(R.string.bill_price));
            msg5.setText(mcontext.getString(R.string.xf_count));
            msg6.setText(mcontext.getString(R.string.bill_subtotal));
        }else if(MyApplication.interfaceVersion.contains("NM")){
            msg1.setText(mcontext.getString(R.string.bill_room));
            msg2.setText(mcontext.getString(R.string.bill_item));
            msg3.setText(mcontext.getString(R.string.xf_count));
            msg4.setText(mcontext.getString(R.string.o_price) + "(" +mcontext.getString(R.string.xf_rmb) + ")");
            msg5.setText(mcontext.getString(R.string.bill_discount) + "(%)");
            msg6.setText(mcontext.getString(R.string.d_price) + "(" +mcontext.getString(R.string.xf_rmb) + ")");
        }
        if(!TextUtils.isEmpty(addmsg)){
            billAddMsg.setText(addmsg);
            billAddMsg.setVisibility(View.VISIBLE);
        }else{
            billAddMsg.setVisibility(View.GONE);
        }
        xfBillAdapter = new XFBillAdapter(mcontext,billList);

        billPricetext.setText(String.format("%.2f",totalP) + " " + mcontext.getString(R.string.xf_rmb));
        billListView.setAdapter(xfBillAdapter);

        Button backBtn = findViewById(R.id.dialog_back);
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dismiss();
            }
        });
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
}